﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQtoStudents
{
    class Student
    {
        private string firstName, lastName, tel, email;

        public string Telephone
        {
            get { return tel; }
            set { tel = value; }
        }

        public string Email
        {
            get { return email; }
            set { email = value; }
        }
        private int fn,group;
        private List<int> marks;

        public List<int> Marks
        {
            get { return marks; }
            set { marks = value; }
        }

        public int GroupNumber
        {
            get { return group; }
            set { group = value; }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }


        public Student(string fname, string lstname,int gr, string phone,string mail)
        {
            group = gr;
            firstName = fname;
            lastName = lstname;
            tel = phone;
            email = mail;
            marks = new List<int>();
        }

        public void AddMark(int mark)
        {
            marks.Add(mark);
        }

        
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<Student> students = new List<Student>();

            students.Add(new Student("Ivan", "Petrov", 2, "02 883", "ivan@abv.bg"));
            students.Add(new Student("Peter", "Petrov", 1, "0883", "ivan@gmail.bg"));
            students.Add(new Student("Georgi", "Ivanov", 2, "0883", "ivan@abv.bg"));
            students.Add(new Student("Dimitar", "Georgiev", 1, "02 0883", "ivan@gmail.bg"));
            students.Add(new Student("Nikola", "Petrov", 2, "0883", "ivan@abv.bg"));
            students.Add(new Student("Julian", "Petrov", 2, "02 0883", "ivan@abv.bg"));

            var LINQquery =
                from s in students
                where s.GroupNumber == 2
                orderby s.FirstName descending
                select s.FirstName + " " + s.LastName;

            foreach(var result in LINQquery)
            {
                Console.WriteLine(result);
            }
            Console.WriteLine("------------------------");

            var extQuery = students.Where(g => g.GroupNumber == 2).OrderBy(x => x.FirstName);
            
            foreach (var s in extQuery)
            {
                Console.WriteLine(s.LastName + " " + s.FirstName + " " + s.GroupNumber);

            }
            Console.WriteLine("------------------------");


            var emailQuery =
                from s in students
                where s.Email.Contains("@abv.bg")
                orderby s.FirstName ascending
                select s.FirstName + " " + s.LastName + " " + s.Email;

            foreach (var result in emailQuery)
            {
                Console.WriteLine(result);
            }
            Console.WriteLine("------------------------");



            var phoneQuery = 
                from s in students
                where s.Telephone.StartsWith("02")
                orderby s.FirstName ascending
                select s.FirstName + " " + s.LastName + " " + s.Telephone;
            foreach (var result in phoneQuery)
            {
                Console.WriteLine(result);
            }
            Console.WriteLine("------------------------");


            var markQuery = 
                from s in students
                where bool delegate(s)  
                    {
                        
                        return true;
                    }
                orderby s.FirstName
                select
        }
    }
}
